<?php
class Comments_Admin_Comments_Controller extends Admin_Controller {

	public $restful = true;

	public function __construct()
	{
		parent::__construct();
		//--Your Code --//
		$this->theme->set_theme("admin") ;
		$this->theme->set_layout("default");
		
		
	}


	public function get_index(){
		
		
		$data['MODE'] = "INDEX";
		$data['comments'] = Comments::get();
		$this->theme->title("Comments Approval");
		return $this->theme->render('comments::admin.comments',$data);
	}


	public function get_update_status($id,$status){


		if($status == '51'){

			$status = '1';

			Comments::where('id', '=', $id)->update(array('status' => $status,));

		}else{
			$status = '51';
			Comments::where('id', '=', $id)->update(array('status' => $status,));
		}

		return Redirect::to("comments/admin/comments");
	}

	public function get_edit($id){
			
		
		$data['MODE'] = "EDIT";
		$data['comments']['info'] = Comments::where('id','=',$id)->first();
			
		$this->theme->title("Edit Comment");
		return $this->theme->render('comments::admin.comments',$data);
	}

	public function post_edit(){
			
		$rules = array(
					
				'comment' => 'required',
					
		);
			
		$v = Validator::make(Input::all(), $rules);
			
		$thisOrderid = Input::get('commentID');
			
			
		if( $v->fails() )
		{
			// code for validation failure :(
			return Redirect::back()
			->with_errors($v)
			->with_input();
		}else{
				
			Comments::where('id','=',$thisOrderid)->update(array(
						
					'comment' => Input::get('comment'),
						
			)
			);
				
			$msg = '<div class="alert alert-info">Successfully Updated....</div>';
			return Redirect::back()->with('message',$msg);
				
		}


	}
	
	public function get_delete($id){
		
		Comments::where('id','=',$id)->delete();
		return Redirect::to("comments/admin/comments");
		
	}
}